﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Office.Interop.Visio;

namespace VisioInteropTest
{
    public partial class Form1 : Form
    {
        
        private string[] shapenameArray;
        private string[] shapepromptArray;
        List<ShapeInfo> list = new List<ShapeInfo>(); 
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            list.Clear();

            //Open file
            string docPath = txtFilePath.Text;
            var visioApp = new Microsoft.Office.Interop.Visio.Application();
            try
            {
                visioApp.Visible = false;
                visioApp.Documents.Open(docPath);

                Page visioPage2 = visioApp.ActivePage;
                int shapeCount2 = visioPage2.Shapes.Count;

                string[] shapeinfoArray = new string[shapeCount2];
                string[] shapenameArray = new string[shapeCount2];
                string[] shapepromptArray = new string[shapeCount2];
                for (int i = 1; i < shapeCount2; i++)
                {
                    Shape shapeItem = visioPage2.Shapes[i];


                    list.Add(new ShapeInfo(){ShapeName = shapeItem.Name, Text = shapeItem.Text});
                    //string property = visioPage2.Shapes[i].get_Cells("Prop.NameOfProperty").Formula;
                }

                //Get Shapes
                //Get
            }
            catch (Exception)
            {
                
                //throw;
            }
            finally
            {
                //close
                //visioApp.ActiveDocument.Close();
                visioApp.Quit();
            }

            dataGridView1.DataSource = list;


        }

        private void Form1_Load(object sender, EventArgs e)
        {
            txtFilePath.Text = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), "Workflow1.vsd");
        }
    }
}
